var platformInfo = {
    isAndroid: navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Linux') > -1,
    isiOS : !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
}

var NativeUtil = {
    set_config: function(pid, type, key, value, extInfoDisplayValue, extInfoId) {
        if (platformInfo.isiOS) {
            // window.webkit.messageHandlers.set_config.postMessage([pid, type, key, value, extInfoDisplayValue, extInfoId])
            window.location.href = "ios://set_config##" + pid + "##" + type + "##" + key + "##" + value + "##" + extInfoDisplayValue + "##" + extInfoId ;
        }
        else {
            window.android.set_config(pid, type, key, value, extInfoDisplayValue, extInfoId)
        }
    },
    request_info: function(pid) {
        if (platformInfo.isiOS) {
            window.webkit.messageHandlers.request_info.postMessage(1)
        } else {
            window.android.request_info(1)
        }
    },
    request_config: function(pid, type) {
        if (platformInfo.isiOS) {
            window.webkit.messageHandlers.request_config.postMessage([pid, type])
        } else {
            window.android.request_config(pid, type)
        }
    },
    delete_config: function(pid, rid, wifiid, deviceid, extinfoId, extInfokey) {
        if (platformInfo.isiOS) {
            window.webkit.messageHandlers.delete_config.postMessage([pid, rid, wifiid, deviceid, extinfoId, extInfokey])
        }
        else {
            window.android.delete_config(pid, rid, wifiid, deviceid, extinfoId, extInfokey)
        }
    },
    request_comm: function(pid, paramsData) {
        if(platformInfo.isiOS){
            window.webkit.messageHandlers.request_comm.postMessage([pid, paramsData])
        }else {
            window.android.request_comm(pid, paramsData);
        }
    },
    request_button: function(pid, key, para) {
        if (platformInfo.isiOS) {
            window.location.href = "ios://request_button##" + pid + "##" + key + "##" + para;
        }else {
            window.android.request_button(pid, key, para);
        }
    }
}

export default NativeUtil